package my.senix.sc.config;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;

import java.util.Arrays;
import java.util.List;
import java.util.Optional;

/**
 * Created by lhs on 2018/11/5.
 */
@Component
public class MyApplicationRunner implements ApplicationRunner {

    @Override
    public void run(ApplicationArguments args) throws Exception {
        System.out.println("我执行了。。。。。");

        args.getOptionNames().forEach(name -> {
            List<String> list = args.getOptionValues(name);

            System.out.println("命令行：" + name + (list.isEmpty() ? " 无value" : Arrays.toString(list.toArray())));
        });

        args.getNonOptionArgs()
                .forEach(arg -> System.out.println("命令行 单一参数：" + arg));
    }

}
